/*
 * @Description: 配置
 * @Author: chenju
 * @Date: 2022-01-24 15:32:46
 * @LastEditors: chenju
 * @LastEditTime: 2022-01-26 17:35:06
 */
import { reactive, markRaw } from 'vue';
import { removeUndefinedParams } from '@/utils/index';
import { GetTaskDataSelectionListParams } from '@/apis/eci/carbonManagement/model/dataListModel';
import { SearchOptionsType } from '@/components/CPageTable';
import { useRoute } from 'vue-router';

export const useDataConfig = () => {
  // 搜索字段及其他
  const searchForm = reactive<GetTaskDataSelectionListParams>({
    taskNo: ''
  });
  const route = useRoute();
  // 页面标题
  const taskNo = route.query.taskNo as any;
  const Title = route.query.title as any;
  const optionsTitle = taskNo + ' ' + Title;
  // 任务编号
  searchForm.taskNo = route.query.taskNo as string;

  // 处理参数
  const handleParams = (): GetTaskDataSelectionListParams => {
    // 参数
    let params: GetTaskDataSelectionListParams = {
      taskNo: searchForm.taskNo
    };
    params = removeUndefinedParams(params);
    return params;
  };

  // 搜索配置
  const searchOptions: SearchOptionsType[] = markRaw([
    {
      name: '排放名称',
      field: 'emissionName',
      type: 'input'
    }
  ]);

  return {
    searchForm,
    handleParams,
    searchOptions,
    optionsTitle
  };
};
